<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>wps app</title>
	</head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<style>
	    #doc > button{width:150px;}
	</style>
	<body>
		<div id="doc">
			<button onclick="loadPlugin()">插件加载</button>     将读取并显示插件信息                <br />
			<button onclick="initPlugin()">插件初始化</button>   将确保启用插件，将可在 console 控制台 通过 navigator.plugins 获取到启用的插件 <br />
			<button onclick="newPlugin()">插件显示</button>      显示插件界面                <br />
			<!-- <button onclick="openFile()">插件实例创建</button>  将提示您选择要选择的具体文档，以显示实例内容界面        <br /> -->
			<!-- <button onclick="disablePlugin()">插件销毁</button>      将禁用插件                    <br />
			<button onclick="delPlugin()">插件删除</button>      将在磁盘级别移除插件(需要注意权限)            <br />
			<button onclick="InitFrame()">插件删除恢复</button>  将在磁盘恢复移除的插件 -->
		</div>
        <div id="message"></div>
  		<div id="wps" align="right" style="width:1200px; height:900px">
        </div>
<script type="text/javascript">
    let pluginName='Kingsoft WPS Plugin';
            let plugin=null;
            function check() {
                if (null === plugin) {
                    document.getElementById("message").innerHTML = '请先确认系统中已安装好插件，并在此处加载了插件';
                    return false;
                } else {
                    return true;
                }
            }
            function loadPlugin() {
                let tags = lnks.plugins().getPluginTags();
                for (var i = 0; i < tags.length; i++) {
                    if (tags[i].name == pluginName) {
                        plugin=tags[i];
                    }
                }
                if (check()) {
                    console.log("loadPlugin check ok");
                    document.getElementById("message").innerHTML = ''
                        + 'Name: ' + plugin.name + '<br />'
                        + 'Des : ' + plugin.description + '<br />'
                        + 'FileName: ' + plugin.filename + '<br />'
                        + 'FullPath: ' + plugin.fullpath;
                } else {
                    console.log("loadPlugin check error");
                }
            }
            function initPlugin() {
                if (check()) {
                    plugin.enabledState=2;// 插件启用
                    document.getElementById("message").innerHTML = '启用操作执行完毕';
                }
            }
            function newPlugin() {
                if (check()) {
                    InitFrame();
                    document.getElementById("message").innerHTML = '显示操作执行完毕';
                }
            }
            function openFile() {
                if (check()) {
                    document.getElementById("message").innerHTML = '<font color="blue">请通过界面中 "文件"->"打开" 选择您要打开的文件</font>';
                }
            }
            function disablePlugin() {
                if (check()) {
                    plugin.enabledState=0;// 插件禁用
                    document.getElementById("wps").innerHTML='';
                    document.getElementById("message").innerHTML = '销毁操作执行完毕';
                }
            }
            function delPlugin() {
                if (check()) {
                    window.lnks.$(`mv /opt/kingsoft /opt/kingsoft2`, ()=>{}, ()=>{});
                    document.getElementById("message").innerHTML = '删除操作执行完毕';
                }
            }
            function recoverPlugin() {
                if (check()) {
                    window.lnks.$(`mv /opt/kingsoft2 /opt/kingsoft`, ()=>{}, ()=>{});
                    document.getElementById("message").innerHTML = '恢复操作执行完毕';
                }
            }
	//obj = document.getElementById("webwps_id");
	var obj = null;
	var app;

	function init(tagID, w, h) {
		var iframe;
		var obj;
		iframe = document.getElementById(tagID);
		var codes=[];   
		//codes.push("");
		codes.push("<object  name='webwps' id='webwps_id' type='application/x-wps'  data='./Normal.dotm'  width='100%'  height='100%'> <param name='Enabled' value='1' />  </object>");
		//说明：wpsextpara参数决定新建还是打开文档
                //新建语法：wpsextpara='-w'
	        //打开语法：wpsextpara='/home/xx/xx.wps'
			//http://192.168.137.80:8080/123.wps
		//wpsextpara='-w'
		//若不需要可删除，不可设置为空

		iframe.innerHTML = codes.join("");
		obj = document.getElementById("webwps_id");


	     	window.onbeforeunload = function() { 
	   		 obj.Application.Quit(); 
       		 };

	
	//解决新建之后立马能输入
/*
		window.onblur = function() {
		    console.log("onblur");
		    obj.sltReleaseKeyboard();
		};
*/

		window.onresize = function() {
		   console.log("ondrag");
		   obj.sltReleaseKeyboard();
		}; 


		return obj;
	}

	function InitFrame() 
	{
		obj = init("wps", "100%", "100%");
		var Interval_control = setInterval(
		function(){
			app = obj.Application;
			if(app && app.IsLoad()){
				clearInterval(Interval_control);
				createDocument();
			}
		},500);
        }

	function createDocument()
	{
		//obj.EnterEditMode();//解决新建之后立马能输入 QuitEditMode  sltReleaseKeyboard
		app.createDocument("wps");
	}
	function openDocumentF()
	{
		var aa = app.openDocument("/home/kylin64/桌面/1.wps", false);
                alert (aa);
	}
	function openDocumentT()
	{
		app.openDocument("/home/kylin64/桌面/11.wps", true);
	}
	function openDocumentRemote()
	{
		var aa = app.openDocumentRemote("http://192.168.137.132:8080/wps/3.wps", false);
                alert (aa);
	} 
	function saveAsQ()
	{
		app.saveAs("/home/kylin64/桌面/123.wps");
	}
	function saveAs()
	{
		app.saveAs();
	}
	function saveURL()
	{
		var aa = app.saveURL("http://192.168.137.132:8080/wps/upload_l.jsp", "3.ofd" );
                alert (aa);
	}
	function printwps()
	{
		app.print();
	}
	function closewps()
	{
		app.close();
	}
	function setToolbarAllVisibleT()
	{
		var aa = app.setToolbarAllVisible(true);
                alert (aa);
	}
	function setToolbarAllVisibleF()
	{
		var aa = app.setToolbarAllVisible(false);
               alert (aa);
	}
	function enableRevisionStart()
	{
		app.enableRevision(true);
	}
	function enableRevisionEnd()
	{
		app.enableRevision(false);
	}
	function insertPicture()
	{
		var aa = app.insertPicture("/home/kylin64/桌面/wps.png");
                alert (aa);
	}
	function insertPictureSize()
	{
		var aa = app.insertPicture("/home/kylin64/桌面/wps.png", 0, 0, 80, 100);
               alert (aa);
	}
	function getText()
	{
		alert(app.getText());
	}
	function setUserName()
	{
		app.setUserName("shenpiyonghu123");
	}
	function getUserName()
	{
		alert(app.getUserName());
	}
	function showRevision0()
	{
		app.showRevision(0);
	}
	function showRevision1()
	{
		app.showRevision(1);
	}
	function showRevision2()
	{
		app.showRevision(2);
	}
	function printRevision0()
	{
		app.printRevision(0);
	}
	function printRevision1()
	{
		app.printRevision(1);
	}
	function printRevision2()
	{
		app.printRevision(2);
	}
	function enableProtectT()
	{
		app.enableProtect(true);
	}
	function enableProtectF()
	{
		app.enableProtect(false);
	}
	function enableRevisionAcceptCommand()
	{
		var aa = app.enableRevisionAcceptCommand(false);
                alert (aa);
	}
	function enableRevisionRejectCommand()
	{
		var bb = app.enableRevisionRejectCommand(false);
                alert (bb);
	}
	function enableCut()
	{
		var aa = app.enableCut(false);
                alert (aa);
	}
	function enableCopy()
	{
		var aa = app.enableCopy(false);
                alert (aa);

	}
	function ExportToOfd()
	{	
		var aa = app.ExportToOfd("/home/kylin64/桌面/11.ofd");
               alert (aa);
	}
	function insertDocumentField()
	{
		var ret = app.insertDocumentField("wps1");
	
	}
	function insertDocumentField2()
	{
		var ret = app.insertDocumentField("wps2");	
	}
        function insertDocumentFieldMultiField()
	{
		app.insertDocumentFieldMultiField("份号,密级,保密期限,紧急程度,后缀标志,发文机关名称,发文顺序号,签发人_1,签发人_2,标题,主送机关,正文,发文机关署名,成文日期,抄送机关_11,抄送机关_12,抄送机关_13,抄送机关_14,抄送机关_15,印发机关,印发日期", "，",",");
		
	}

	function getAllDocumentField()
	{
		var fieldsname = app.getAllDocumentField();
		var strs = new Array();
		strs = fieldsname.split(",");
		alert(strs);
	}
	function deleteDocumentField()
	{
		var ret = app.deleteDocumentField("wps1");
               alert (ret);
	}
	function showDocumentField()
	{
		app.showDocumentField("wps1",true);
	}
	function showDocumentField2()
	{
		app.showDocumentField("wps1",false);
	}
	function getDocumentFieldValue()
	{
		var ret = app.getDocumentFieldValue("wps1");
		alert(ret);
	}
	function enableDocumentField()
	{
		app.enableDocumentField("wps1",true);
	}
	function enableDocumentField2()
	{
		app.enableDocumentField("wps1",false);
	}
	function insertDocument()
	{
		var aa = app.insertDocument("正文","/home/kylin64/桌面/wps.wps");
               alert (aa);
	}
	function insertDocument2()
	{
		var aa = app.insertDocument("正文","ftp://ftptest:123456@192.168.158.73/test/ftp.doc");
               alert (aa);
	}
	function isExists()
	{
		var aa = app.isExists("wps1");
                alert (aa);
	}	
	function backspace()
	{
		app.backspace();
	}
	function cursorToDocumentField()
	{
		app.cursorToDocumentField("wps1",4);
	}
      function cursorToDocumentField5()
	{
		app.cursorToDocumentField("wps1",5);
	}
	function insertText()
	{
		app.insertText("kingsoft");
	}
	function setDocumentId()
	{
		app.setDocumentId("kingsoft");
	}
	function getDocumentId()
	{
		var id = app.getDocumentId();
		alert(id);
	}
	function setDocumentType()
	{
		app.setDocumentType("纪要");
	}
	function getDocumentType()
	{
		var type = app.getDocumentType();
		alert(type);
	}
	function showDocumentMultiField()
	{
		var ret = app.showDocumentMultiField("份号,密级,保密期限,紧急程度,后缀标志,发文机关名称,发文机关代字,年份,发文顺序号,签发人_1,签发人_2,标题,主送机关,正文,发文机关署名,成文日期,抄送机关_1,抄送机关_2,抄送机关_3,抄送机关_4,抄送机关_5,印发机关,印发日期", ",", true);
		alert(ret);
	}
	function deleteDocumentMultiField()
	{
		app.deleteDocumentMultiField("份号,密级,保密期限,紧急程度,后缀标志,发文机关名称,发文机关代字,年份,发文顺序号,签发人_1,签发人_2,标题,主送机关,正文,发文机关署名,成文日期,抄送机关_1,抄送机关_2,抄送机关_3,抄送机关_4,抄送机关_5,印发机关,印发日期",",", true);
	}

	function setDocumentField1()
	{	
		var ret = app.getAllDocumentField();
		var fieldArr = ret.split(",");
		var yus = "";
		var values = "";
		for(var i=0;i<fieldArr.length;i++){
			var yu = fieldArr[i];
			if(yu=='正文'){
				values += '正文'
			}else{
			values+=(i+1);
				
			}
			yus+=yu;
			if(i!=fieldArr.length-1){
				yus+="@#_*@";
				values+="@#_*@";
			}
		}
		
		var aa = app.setDocumentMultiField(yus,values, true);		
                alert (aa);
	}
	function setDocumentField2()
	{		
		var ret = app.getAllDocumentField();
		var fieldArr = ret.split(",");
		var yus = "";
		var values = "";
		for(var i=0;i<fieldArr.length;i++){
			var yu = fieldArr[i];
			if(yu=='正文'){
				continue;
			}else{
			values+=(i+100);
				
			}
			yus+=yu;
			if(i!=fieldArr.length-1){
				yus+="@#_*@";
				values+="@#_*@";
			}
		}
		
		var aa = app.setDocumentMultiField(yus,values, true);
                alert (aa);
		
	}
       function fileVisible()
	{
		var ret = app.showCommandByName("Menu Bar", 1, true);
		alert(ret);
	}
	 function Bulid()
	{
		var ret = app.get_Build();
               // var ret = app.Bulid;
		alert(ret);
	}
	function getPluginVersion()
	{
		var ret = app.getPluginVersion();
               // var ret = app.Bulid;
		alert(ret);
	}

         function Clipboardcallback()
        {
	  alert("Clipboardcallback");
        }
         function ClipboardRegister()
        {

	   obj.ClipbroadCheck();
	   alert(app.registerEvent("DIID_ApplicationEvents4","ClipboardChange", "Clipboardcallback"));
	
         }

          function put_PrintDrawingObjects()
 
	 {
	  	
           var aa = app.Options.put_PrintDrawingObjects(true);
           //alert (aa);
	 }
	
	
	  function put_PrintHiddenText()
         {

           var aa = app.Options.put_PrintHiddenText(true);
           //alert (aa);
	
         }
	
          function put_PrintHiddenTextMode1()
         {

           var aa = app.Options.put_PrintHiddenTextMode(0);
           //alert (aa);
	
         }
          function put_PrintHiddenTextMode2()
         {

           var aa = app.Options.put_PrintHiddenTextMode(1);
           //alert (aa);
	
         }
          function put_PrintHiddenTextMode3()
         {

           var aa = app.Options.put_PrintHiddenTextMode(2);
           //alert (aa);
	
          }
         function setOfdServiceProviderSuwell()
         {
          var a = app.get_OfdExportOptions();
          var ret = a.put_SelectServiceProvider(0);
          alert(ret);
         }
	function setServiceProviderFoxit()
	{
		var a = app.get_OfdExportOptions();
		var ret = a.put_SelectServiceProvider(1);
		alert(ret);
	}

	function EventCallBack2(doc,cancel)
	{
		alert("EventCallBack2");
		cancel.SetValue(true);
		alert(cancel.GetValue());
	}

	function RegisterBeforeCloseEvent()
	{
		var app = obj.Application;
		var ret = app.registerEvent("DIID_ApplicationEvents4","DocumentBeforeClose","EventCallBack2");
		alert("ret--"+ret);
	}

       function UnRegisterBeforeCloseEvent()
	{
		var app = obj.Application;
		var ret = app.unRegisterEvent("DIID_ApplicationEvents4","DocumentBeforeClose","EventCallBack2");
		alert("ret--"+ret);
	}
      function getFileSize(){
		var filename = prompt("请输入文件路径","");
		var saveformat = prompt("请输入文件后缀，为空默认为wps","")
		alert(app.getFileSize(filename,saveformat));
	}
	
	function saveURL2() {
		var name=prompt("请输入要保存的名称","test1.ofd")
		if (name!=null && name!=""){
			var ret = app.saveURL("http://192.168.158.73:8080/wps/upload_w.jsp", name,"aa","bb");
			alert(ret);
		}
		

    }
    function saveURL3() {
   //通过设置ConvertSummaryInfo的值控制是否导出文档信息
    var pdfOptions = app.get_PdfExportOptions(); 
    var ret = pdfOptions.put_ConvertSummaryInfo(false); 
     
   //DocFrame.ActiveDocument.Application.PdfExportOptions.ConvertSummaryInfo = false;
	
    
		var name=prompt("请输入要保存的名称","test1.ofd")
		if (name!=null && name!=""){
			var ret = app.saveURL("http://192.168.158.73:8080/wps/upload_w.jsp", name,"aa","bb");
			alert(ret);
		}
		

    }
	
	function setForceBackUpEnabled1()
	{
		app.setForceBackUpEnabled(false);
	}
       function setForceBackUpEnabled2()
	{
		app.setForceBackUpEnabled(true);
	}
	function FullScreen(){
		app.FullScreen();
	}
		function disable_ctrl_p(){
		app.DisabledHotKeys = "(ctrl+p)";
	}
	function enable_ctrl_p(){
		app.DisabledHotKeys = "";
	}
		function insert_document(){
		alert(app.insertDocument('正文', 'ftp://ftptest:123456@192.168.158.73/test/ftp.doc'));
	}
       function menuvisible()
       {
                var Bars  = app.get_CommandBars();
	        var filebar = Bars.get_Item("file");
		var spControls = filebar.get_Controls();

		var Controlpdf = spControls.get_Item(25);
		alert(Controlpdf.get_Caption());
		Controlpdf.put_Visible(false);

		var Control = spControls.get_Item(26);
		alert(Control.get_Caption());
		Control.put_Caption("输出为OFD格式(&G)...");
		alert(Control.get_Caption());
		Control.put_Visible(false);

    }

</script>





	</body>
</html>
